#coding=utf-8
import cv2
import numpy as np
import matplotlib as plt

def blur(img):
    ret_blur = cv2.blur(img, (5,5))
    ret_gaussblur=cv2.GaussianBlur(img,(5,5),1.5)
    
    return ret_blur,ret_gaussblur



def sobel(img):  
   
    x = cv2.Sobel(img,cv2.CV_16S,1,0)
    y = cv2.Sobel(img,cv2.CV_16S,0,1)
    absX = cv2.convertScaleAbs(x) # 转回uint8
    absY = cv2.convertScaleAbs(y)
#     ret_sobel = cv2.addWeighted(absX,0.5,absY,0.5,0)
    
    ret_sobel=cv2.Sobel(img,cv2.CV_16S,1,1)
    ret_sobel=cv2.convertScaleAbs(ret_sobel)
    
        
    return absX,absY,ret_sobel


def Laplacian(img):
  
    gray_lap = cv2.Laplacian(img,cv2.CV_16S,ksize = 3)
    ret_lap = cv2.convertScaleAbs(gray_lap)
    
    return ret_lap

def Canny(img):
    ret_canny = cv2.Canny(img, 50, 150)
    
    return ret_canny



if __name__ == '__main__':
    img = cv2.imread("..//img//lena.jpg", 0)
    ret_blur,ret_gaussblur=blur(img)
    absX,absY,ret_sobel=sobel(img)
    ret_lap=Laplacian(img)
    ret_canny=Canny(img)
    
    
    cv2.imshow("Origin", img)
#     cv2.imshow("Blur", ret_blur)
#     cv2.imshow("GaussResult", ret_gaussblur)
    
#     cv2.imshow("absX", absX)
#     cv2.imshow("absY", absY)
    cv2.imshow("ret_sobel", ret_sobel)
    cv2.imshow("ret_lap", ret_lap)
    cv2.imshow("ret_canny", ret_canny)
    
    cv2.waitKey(0)
    cv2.destroyAllWindows()
    
    
    